home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
program
/
3dview12.zip
/
3DFUNC.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-28
|
15KB
|
481 lines
#include <stdio.h>
#include <bios.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <i86.h>
#include <string.h>
#include "defines.hpp"
#include "vesa.hpp"
#include "3d.hpp"
#include "vesa3d.hpp"
#include "misc.hpp"
#include "mouse.hpp"
typedef double T3DFunction(double, double);
void ShowFunction( T3DFunction f, double X1, double Y1, double X2, double Y2,
long m, long n, DWORD PalStart ) {
long* fPoints = new long [(m+1)*(n+1)];
double DX = (X2-X1)/n;
double DY = (Y2-Y1)/m;
for ( long i = 0; i <= m; i++ ) {
for ( long j = 0; j <= n; j++ ) {
fPoints[i*(n+1)+j] = _3D_NewPoint( X1+j*DX, Y1+i*DY, f(X1+j*DX, Y1+i*DY) );
};
};
for ( i = 0; i < m; i++ ) {
for ( long j = 0; j < n; j++ ) {
VESA3D_New3DQuad( fPoints[i*(n+1)+j], fPoints[i*(n+1)+j+1],
fPoints[(i+1)*(n+1)+j+1], fPoints[(i+1)*(n+1)+j],
PalStart, Doublesided, GouraudShadedZBuf );
};
};
};
void ShowFunction_Tex( T3DFunction f, double X1, double Y1, double X2, double Y2,
long m, long n, VESA3D_Texture &TEX ) {
long* fPoints = new long [(m+1)*(n+1)];
double DX = (X2-X1)/n;
double DY = (Y2-Y1)/m;
double TEXDX = double(TEX.TDX) / n;
double TEXDY = double(TEX.TDY) / m;
for ( long i = 0; i <= m; i++ ) {
for ( long j = 0; j <= n; j++ ) {
fPoints[i*(n+1)+j] = _3D_NewPoint( X1+j*DX, Y1+i*DY, f(X1+j*DX, Y1+i*DY) );
};
};
for ( i = 0; i < m; i++ ) {
for ( long j = 0; j < n; j++ ) {
_3D_NewObject(
new _3D_Triangle( fPoints[i*(n+1)+j], j*TEXDX, i*TEXDY,
fPoints[i*(n+1)+j+1], (j+1)*TEXDX, i*TEXDY,
fPoints[(i+1)*(n+1)+j+1], (j+1)*TEXDX, (i+1)*TEXDY,
&TEX, Doublesided, Rectangle, TexturedZBuf ));
_3D_NewObject(
new _3D_Triangle( fPoints[(i+1)*(n+1)+j+1], (j+1)*TEXDX, (i+1)*TEXDY,
fPoints[(i+1)*(n+1)+j], j*TEXDX, (i+1)*TEXDY,
fPoints[i*(n+1)+j], j*TEXDX, i*TEXDY,
&TEX, Doublesided, Rectangle, TexturedZBuf ));
};
};
};
void ShowTitle() {
printf( "# 3D-BMP-Viewer V1.2 (w) by P.Kayser 1996 \n" );
printf( "# EMAIL : p.kayser@tu-bs.de\n" );
};
void ShowHeader() {
ShowTitle();
printf( "# usage : 3DVIEW (-abdmz) <File(.BMP)> (<Mode>)\n" );
printf( "# \n" );
printf( "# options\n" );
printf( "# -a : show additional informations.\n" );
printf( "# -b : disable bitmap.\n" );
printf( "# -d<dist> : distance. <dist> from 0.01 (far) to 3 (near).\n" );
printf( "# -m : enable mouse-control.\n" );
printf( "# -z : enable z-buffer.\n" );
};
void ShowAddInfo() {
printf( "# \n" );
printf( "# Needs VBE version 2.0.\n" );
printf( "# Only 256-color-modes allowed.\n" );
printf( "# The bitmap must be 'Windows-RGB-Encoded' and should have\n" );
printf( "# a maximum of 192 colors. Colors 192..255 are used for the\n" );
printf( "# border.\n" );
printf( "# \n" );
printf( "# 256-Color-VBE-Modes :\n" );
printf( "# 640x480 : 101 | 800x600 : 103 | 1024x768 : 105\n" );
};
double Phi = 0;
double G( double x, double y ) {
double g = 1-2*x*x-4*y*y;
if ( g >= 0 )
return sqrt(g);
else
return 0;
};
double J( double x, double y ) {
double g = 1-2*x*x-4*y*y;
if ( g >= 0 )
return -sqrt(g);
else
return 0;
};
double H( double x, double y ) {
double h = 1-x;
return h;
};
void PF( _3D_Point &P ) {
P.Z = G(P.X,P.Y);
};
void main( int argc, char *argv[] ) {
Boolean ShowBitmap = True;
Boolean ShowAddInfos = False;
Boolean WithZBuffer = False;
Boolean MouseControl = False;
double Distance = 1;
int CmdCount = 1;
char Buffer [15];
double MinZoom = 0.01;
double MaxZoom = 3;
double NormZoom = 1;
if ( argc == CmdCount ) {
VESA_SetTextMode();
ShowHeader();
return;
};
while ( (argv[CmdCount])[0] == '-' ) {
int OptCount = 1;
while ( OptCount < strlen( argv[CmdCount] ) ) {
switch ( (argv[CmdCount])[OptCount] ) {
case 'a' :
ShowAddInfos = True;
break;
case 'b' :
ShowBitmap = False;
break;
case 'd' :
Distance = strtod( strncpy( Buffer,
&(argv[CmdCount])[OptCount+1],
strlen( argv[CmdCount] ) - OptCount ),
NULL );
if ( Distance < MinZoom || Distance > MaxZoom )
Distance = NormZoom;
OptCount = strlen ( argv[CmdCount] );
break;
case 'z' :
WithZBuffer = True;
break;
case 'm' :
MouseControl = True;
break;
default:
VESA_SetTextMode();
ShowTitle();
printf( "\n" );
printf( "ERROR : '%c' is an unknown option !\n" , argv[CmdCount][OptCount] );
return;
}
OptCount++;
};
CmdCount++;
};
if ( ShowAddInfos == True ) {
VESA_SetTextMode();
ShowHeader();
ShowAddInfo();
return;
};
static VESA3D_Texture TEX;
char* Filename = new char [256];
strcpy( Filename, argv[CmdCount] );
if ( VESA3D_LoadTexture( Filename, TEX ) != 0 )
if ( VESA3D_LoadTexture( strcat( Filename, ".BMP" ), TEX ) != 0 ) {
VESA_SetTextMode();
ShowTitle();
printf( "\n" );
printf( "ERROR : Could not open .BMP-File !\n" );
return;
};
VESA3D_ConvertTexture( TEX );
CmdCount++;
WORD Mode;
if ( argc == CmdCount ) {
Mode = 0x0101;
}
else {
Mode = WORD( strtoul( argv[CmdCount], NULL, 16 ) );
};
VESA_SetTextMode();
ShowTitle();
if ( VESA_InitMode( Mode ) != 0 ) {
return;
};
if ( VESA_BpP != 8 ) {
VESA_SetTextMode();
ShowTitle();
printf( "\n" );
printf( "ERROR: Not a 256-Color-Mode !\n" );
return;
};
VESA3D_Init();
if ( WithZBuffer == True )
VESA3D_MakeZBuffer();
/*
for ( int i = 47; i >= 0; i-- )
VESA_SetColor8B( WORD(239-i) ,
WORD(32+i*5/2),
WORD(32+i*5/2),
WORD(32+i*5/2) );
for ( i = 15; i >= 0; i-- )
VESA_SetColor8B( WORD(255-i),
WORD(128+i*8),
WORD(128+i*8),
WORD(128+i*8) );
VESA_SetColor8B( 0, 0, 0, 0 );
if ( ShowBitmap == True )
VESA3D_SetTexturePalette( TEX, 192 );
double px, py;
if ( TEX.TDY > TEX.TDX ) {
px = 1;
py = double(TEX.TDY) / TEX.TDX;
}
else {
py = 1;
px = double(TEX.TDX) / TEX.TDY;
};
long p1 = _3D_NewPoint( 0, py, 0 );
long p2 = _3D_NewPoint( px, py, 0 );
long p3 = _3D_NewPoint( px, 0, 0 );
long p4 = _3D_NewPoint( 0, 0, 0 );
double dx = 0.25, dz = 0.06;
long p5 = _3D_NewPoint( -dx, -dx, dz );
long p6 = _3D_NewPoint( -dx, -dx, -dz );
long p7 = _3D_NewPoint( px+dx, -dx, dz );
long p8 = _3D_NewPoint( px+dx, -dx, -dz );
long p9 = _3D_NewPoint( -dx, py+dx, dz );
long p10 =